<template>
  <div class="battle-detail-bottom" v-loading="loading" :class="{ 'is-show': visible }">
    <div class="battle-detail-bottom-title" @click="close">
      <img src="@/static/img/battle/icon-fold.png" alt="" />
      收起
    </div>
    <div class="battle-detail-skin-list battle-scrollbar">
      <div class="battle-detail-skin-item" v-for="skin in skinList" :key="skin.item_id">
        <img :src="skin.image_url" />
        <div class="battle-detail-skin-item-name text-overflow">{{ skin.item_name }}</div>
        <div class="battle-detail-skin-item-prob">
          概率：{{ Number((skin.real_probability * 100).toFixed(3)) }}%
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import BoxService from "@/services/BoxService";
import { SkinItem } from "@/types";
import { returnStatement } from "@babel/types";
import { defineComponent, toRefs, reactive } from "vue";

export default defineComponent({
  setup() {
    const state = reactive({
      skinList: [] as SkinItem[],
      loading: false,
      visible: false,
    });

    let boxId = -1;
	
	let roomId = -1;

    const getSkinList = () => {
      state.loading = true;

      return BoxService.battleBoxSkin({
		room_id: roomId,
        box_id: boxId,
        page_size: 999,
      })
        .then((response) => {
          state.skinList = response.data.data.list.sort((a, b) => b.price - a.price);
        })
        .finally(() => {
          state.loading = false;
        });
    };

    return {
      ...toRefs(state),
      open: (id: number, rid: number) => {
        if (state.visible && id === boxId) return;
		
        if (!state.visible) {
          state.skinList = [];
        }

        boxId = id;
		roomId = rid;
        state.visible = true;
        getSkinList();
      },
      close: () => {
        state.visible = false;
      },
    };
  },
});
</script>

<style lang="scss" scoped>
.battle-detail-bottom {
  position: fixed;
  width: 100%;
  left: 0;
  bottom: -300px;
  background: #28253b;
  transition: bottom 0.3s linear;
  // height: 261px;
  box-shadow: 0 -5px 10px #111;
  z-index: 2;

  &.is-show {
    bottom: 0;
  }

  .battle-detail-bottom-title {
    line-height: 50px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;

    img {
      width: 12px;
      margin-right: 8px;
    }
  }

  .battle-detail-skin-list {
    overflow: auto;
    display: flex;
    flex-wrap: nowrap;

    .battle-detail-skin-item {
      width: 167px;
      margin-right: 1px;
      box-sizing: border-box;
      flex: none;
      text-align: center;
      height: 201px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      padding: 0 30px;

      &:last-child {
        margin-right: 0;
      }

      img {
        width: 100%;
      }

      .battle-detail-skin-item-name {
        font-size: 14px;
        line-height: 19px;
        color: #ffffff;
        margin-top: 22px;
        width: 100%;
      }

      .battle-detail-skin-item-prob {
        font-size: 12px;
        color: #ffb300;
        margin-top: 6px;
      }
    }
  }
}
</style>

<style scoped lang="scss">
@media screen and (max-width: 600px) {
  .battle-detail-bottom {
    height: 194px;

    .battle-detail-bottom-title {
      line-height: 30px;
      font-size: 12px;
    }

    .battle-detail-skin-list {
      .battle-detail-skin-item {
        width: 130px;
        height: 160px;
        padding: 0 10px;
      }
    }
  }
}
</style>
